#include <esp_log.h>
#include <esp_err.h>
#include <nvs.h>
#include <nvs_flash.h>
#include <driver/gpio.h>
#include <esp_event.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <iostream>
#include "application.h"
#include "system_info.h"

#include "esp_tts.h"
#include "esp_tts_voice_xiaole.h"
#include "esp_tts_voice_template.h"
#include "esp_tts_player.h"

#define TAG "main"
esp_tts_handle_t tts_handle = NULL;

std::string_view my_commands[] = {
    "哥们， 我要大力击球啦",
    "伙计， 来个中力击球么",
    "亲， 小力击球，走起"
};

int voice_play(int i)
{
    std::string_view prompt1 = "我不知道怎样做";

    return 0;

    auto& app = Application::GetInstance();
    printf("%s:%d: %d\n", __func__,  __LINE__, i);
    
    i -= 2;
    if (i >= 0 && i < 3)
         app.PlaySound(my_commands[i]);
    else
        app.PlaySound(prompt1); 
    std::cout << prompt1 << std::endl;

    app.PlaySound(prompt1);
    return 0;
}


extern "C" void app_main(void)
{
    // Initialize the default event loop
    ESP_ERROR_CHECK(esp_event_loop_create_default());
    std::string_view prompt1 = "我不知道怎样做"; 

    //voic_tts();

   // voice_play(0);

    // Initialize NVS flash for WiFi configuration
    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
        ESP_LOGW(TAG, "Erasing NVS flash to fix corruption");
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK(ret);

    // Launch the application
    auto& app = Application::GetInstance();
    app.Start();
    //app.PlaySound(prompt1);
    voice_play(2);
voice_play(3);
voice_play(4);
voice_play(5);
}
